home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
src
/
fig19_12.jar
/
Ch19
/
Fig19_12
/
Fig19_12.cpp
Wrap
C/C++ Source or Header
|
1997-11-10
|
864b
|
37 lines
// Fig. 19.12: fig19_12.cpp
// Demonstrating input from an istringstream object.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
main()
{
string input( "Input test 123 4.7 A" );
istringstream inputString( input );
string string1, string2;
int i;
double d;
char c;
inputString >> string1 >> string2 >> i >> d >> c;
cout << "The following items were extracted\n"
<< "from the istringstream object:"
<< "\nstring: " << string1
<< "\nstring: " << string2
<< "\n int: " << i
<< "\ndouble: " << d
<< "\n char: " << c;
// attempt to read from empty stream
long l;
if ( inputString >> l )
cout << "\n\nlong value is: " << l << endl;
else
cout << "\n\ninputString is empty" << endl;
return 0;
}